package com.qs.questionnairesurveysystem.service.impl;

import com.qs.questionnairesurveysystem.entity.Admin;
import com.qs.questionnairesurveysystem.mapper.AdminMapper;
import com.qs.questionnairesurveysystem.service.AdminService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class AdminServiceImpl implements AdminService {

    @Autowired
    private AdminMapper adminMapper;

    @Override
    public Admin getAdminById(Long adminId) {
        return adminMapper.findById(adminId);
    }

    @Override
    public List<Admin> getAllAdmins() {
        return adminMapper.findAll();
    }

    @Override
    public int createAdmin(Admin admin) {
        return adminMapper.insertAdmin(admin);
    }

    @Override
    public int updateAdmin(Admin admin) {
        return adminMapper.updateAdmin(admin);
    }

    @Override
    public int deleteAdmin(Long adminId) {
        return adminMapper.deleteAdmin(adminId);
    }

    @Override
    public Admin getAdminByName(String username) {
        return adminMapper.getAdminByName(username);
    }

    // 加载用户
    public Admin loadUserByUsername(String username) {
        // 在真实的实现中，你需要从数据库中加载用户信息
        return new Admin(username, "password");
    }
}
